package com.wangzeqi.changliaoba.messege;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.wangzeqi.changliaoba.R;

/**
 * Created by dllo on 16/3/7.
 */
public class GridViewOfMessegeAdapter extends BaseAdapter {
    private Context context;
    private int[] imageID = new int[]{R.mipmap.messege_tupian,R.mipmap.messege_xiaoshipin,R.mipmap.messege_weizhi,R.mipmap.messege_shoucang,
            R.mipmap.messege_yuyinliaotian,R.mipmap.messege_shipin,R.mipmap.messege_hongbao,R.mipmap.messege_xiuxianyule,};
    private String[] names = new String[]{"图片","小视频","位置","收藏","语音","视频","红包","娱乐"};
    public GridViewOfMessegeAdapter(Context context) {
        this.context = context;
    }

    @Override
    public int getCount() {
        return 8;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_gridview,null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch ( position){
                    case 0:
                        Intent intent = new Intent(context,SelectSendPicture.class);
                        context.startActivity(intent);
                        break;
                }
                Toast.makeText(context, "position:" + position, Toast.LENGTH_SHORT).show();
            }
        });
        holder.imageView.setImageResource(imageID[position]);
        holder.textView.setText(names[position]);
        return convertView;
    }

    class ViewHolder {
        private ImageView imageView;
        private TextView textView;

        public ViewHolder(View view) {
            imageView = (ImageView) view.findViewById(R.id.gridview_iv);
            textView = (TextView) view.findViewById(R.id.gridview_tv);
        }
    }
}
